{-# LANGUAGE TypeOperators              #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# OPTIONS -Wall #-}

--------------------------------------------------------------------------------
-- |
-- Module      :  Orca.Csound.SignalGenerators
-- Copyright   :  (c) Stephen Tetley 2013
-- License     :  BSD3
--
-- Maintainer  :  stephen.tetley@gmail.com
-- Stability   :  unstable
-- Portability :  GHC
--
-- Signal generating opcodes.
--
--------------------------------------------------------------------------------

module Orca.Csound.SignalGenerators
  (

  -- * Linear and exponential generators
    cs_line
  , cs_expon
  , cs_linseg
  , cs_linsegr
  , cs_expseg
  , cs_expsegr
  , cs_expsega
  , cs_transeg

  , cs_adsr
  , cs_adsr_

  , cs_madsr
  , cs_madsr_
  , cs_xadsr
  , cs_xadsr_
  , cs_mxadsr
  , cs_mxadsr_

  -- * Table access
  , cs_table
  , cs_table_

  , cs_tablei
  , cs_tablei_
  
  , cs_table3
  , cs_table3_

  , cs_oscil1
  , cs_oscil1i
  , cs_osciln

  -- * Phasors
  , cs_phasor
  , cs_phasor_
  , cs_phasorbnk
  , cs_phasorbnk_


  -- * Basic oscillators
  , cs_oscil
  , cs_oscil_
  , cs_oscili
  , cs_oscili_
  , cs_oscil3
  , cs_oscil3_
  , cs_poscil
  , cs_poscil_
  , cs_poscil3
  , cs_poscil3_
  , cs_lfo
  , cs_lfo_

  -- * Dynamic spectrum oscillators
  , cs_buzz
  , cs_buzz_
  , cs_gbuzz
  , cs_gbuzz_
  , cs_vco

  -- * Additive synthesis / resynthesis
  , cs_adsyn
  , cs_adsynt
  , cs_adsynt_
  , cs_hsboscil
  , cs_hsboscil_

  -- * FM synthesis
  , cs_foscil
  , cs_foscil_
  , cs_foscili
  , cs_foscili_
  , cs_fmvoice
  , cs_fmbell
  , cs_fmrhode
  , cs_fmwurlie
  , cs_fmmetal
  , cs_fmb3
  , cs_fmpercfl

  -- * Sample playback - full spec versions todo
  , cs_loscil
  , cs_loscilS
  , cs_loscil3
  , cs_loscil3S
  , cs_lposcil
  , cs_lposcil3

  -- * Granular synthesis
  , cs_fof
  , cs_fof2
  , cs_fog
  , cs_grain
  , cs_grain2
  , cs_grain3
  , cs_granule
  , cs_partikkel

  -- * Models and emulations
  , cs_moog
  , cs_shaker
  , cs_marimba
  , cs_vibes
  , cs_mandol
  , cs_gogobel
  , cs_voice
  , cs_lorenz
  , cs_planet

  -- * Random noise generators
  , cs_rand
  , cs_randh
  , cs_randi
  , cs_linrand
  , cs_trirand
  , cs_exprand
  , cs_bexprand
  , cs_cauchy
  , cs_pcauchy
  , cs_poisson
  , cs_gauss
  , cs_weibull
  , cs_betarand
  , cs_unirand

  -- * Waveguide physical modeling
  , cs_pluck
  , cs_repluck
  , cs_wgbow
  , cs_wgbowedbar
  , cs_wgbrass
  , cs_wgclar
  , cs_wgflute
  , cs_wgpluck
  , cs_wgpluck2
  , cs_wguide1
  , cs_wguide2    

  ) where



import Orca.Csound.Monad
import Orca.Csound.Syntax


--------------------------------------------------------------------------------
-- Linear and Exponential generators



cs_line :: forall rate. KA_Signal rate 
        => IFloat -> IFloat -> IFloat -> Orca (Sig rate)
cs_line ia idur1 ib = 
    genOpcode1 rid "line" [ getPExpr ia, getPExpr idur1
                          , getPExpr ib ]
  where
    rid = genRate (undefined :: rate)



cs_expon :: forall r1. KA_Signal r1 
         => IFloat -> IFloat -> IFloat -> Orca (Sig r1)
cs_expon ia idur1 ib = 
    genOpcode1 rid "expon" [ getPExpr ia, getPExpr idur1
                           , getPExpr ib ]
  where
    rid = genRate (undefined :: r1)




cs_linseg :: forall r1. KA_Signal r1
          => IFloat -> [IFloat ::: IFloat] -> Orca (Sig r1)
cs_linseg ia xss =  
    genOpcode1 rid "linseg" $ getPExpr ia : concatMap fn xss
  where
    fn (idur ::: ib) = [getPExpr idur, getPExpr ib]
    rid              = genRate (undefined :: r1)

    


cs_linsegr :: forall r1. KA_Signal r1
           => IFloat -> [IFloat ::: IFloat] -> IFloat ->  IFloat 
           -> Orca (Sig r1)
cs_linsegr ia xss irel iz =
    genOpcode1 rid "linsegr" $ getPExpr ia : concatMap fn xss ++ release
  where
    fn (idur ::: ib) = [getPExpr idur, getPExpr ib]
    release          = [getPExpr irel, getPExpr iz]
    rid              = genRate (undefined :: r1)



cs_expseg :: forall r1. KA_Signal r1 
          => IFloat -> [IFloat ::: IFloat] -> Orca (Sig r1)
cs_expseg ia xss = 
    genOpcode1 rid "expseg" $ getPExpr ia : concatMap fn xss
  where
    fn (idur ::: ib) = [getPExpr idur, getPExpr ib]
    rid              = genRate (undefined :: r1)

cs_expsegr :: forall r1. KA_Signal r1
           => IFloat -> [IFloat ::: IFloat] -> IFloat -> IFloat 
           -> Orca (Sig r1)
cs_expsegr ia xss irel iz = 
    genOpcode1 rid "expsegr" $ getPExpr ia : concatMap fn xss ++ release
  where
    fn (idur ::: ib) = [getPExpr idur, getPExpr ib]
    release          = [ getPExpr irel, getPExpr iz ]
    rid              = genRate (undefined :: r1)

cs_expsega :: IFloat -> [IFloat ::: IFloat] -> Orca ASig
cs_expsega ia xss =
    genOpcode1 A_RATE "expsega" $ getPExpr ia : concatMap fn xss 
  where
    fn (idur ::: ib) = [getPExpr idur, getPExpr ib]
 

cs_transeg :: forall r1. KA_Signal r1
           => IFloat -> [IFloat ::: IFloat ::: IFloat] -> Orca (Sig r1)
cs_transeg ia xss = 
    genOpcode1 rid "transeg" $ getPExpr ia : concatMap fn xss 
  where
    fn (idur ::: (itype ::: ib)) = [ getPExpr idur, getPExpr itype
                                   , getPExpr ib ]
    rid                          = genRate (undefined :: r1)


cs_adsr :: forall r1. KA_Signal r1 
        => IFloat -> IFloat -> IFloat -> IFloat -> Orca (Sig r1)
cs_adsr iatt idec islev irel = 
    genOpcode1 rid "adsr" [ getPExpr iatt,  getPExpr idec
                          , getPExpr islev, getPExpr irel ]
  where
    rid = genRate (undefined :: r1)
                   


cs_adsr_ :: forall r1. KA_Signal r1 
         => IFloat -> IFloat -> IFloat -> IFloat -> IFloat 
         -> Orca (Sig r1)
cs_adsr_ iatt idec islev irel idel = 
    genOpcode1 rid "adsr" [ getPExpr iatt,  getPExpr idec
                          , getPExpr islev, getPExpr irel
                          , getPExpr idel ]
  where
    rid = genRate (undefined :: r1)


cs_madsr :: forall r1. KA_Signal r1
         => IFloat -> IFloat -> IFloat -> IFloat -> Orca (Sig r1)
cs_madsr iatt idec islev irel = 
    genOpcode1 rid "madsr" [ getPExpr iatt,  getPExpr idec
                           , getPExpr islev, getPExpr irel ]
  where
    rid = genRate (undefined :: r1)


cs_madsr_ :: forall r1. KA_Signal r1
          => IFloat -> IFloat -> IFloat -> IFloat -> IFloat 
          -> Orca (Sig r1)
cs_madsr_ iatt idec islev irel idel = 
    genOpcode1 rid "madsr" [ getPExpr iatt,  getPExpr idec
                           , getPExpr islev, getPExpr irel
                           , getPExpr idel ]
  where
    rid = genRate (undefined :: r1)


cs_xadsr :: forall r1. KA_Signal r1
         => IFloat -> IFloat -> IFloat -> IFloat -> Orca (Sig r1)
cs_xadsr iatt idec islev irel = 
    genOpcode1 rid "xadsr" [ getPExpr iatt,  getPExpr idec
                           , getPExpr islev, getPExpr irel ]
  where
    rid = genRate (undefined :: r1)


cs_xadsr_ :: forall r1. KA_Signal r1
          => IFloat -> IFloat -> IFloat -> IFloat -> IFloat 
          -> Orca (Sig r1)
cs_xadsr_ iatt idec islev irel idel = 
    genOpcode1 rid "xadsr" [ getPExpr iatt,  getPExpr idec
                           , getPExpr islev, getPExpr irel
                           , getPExpr idel ]
  where
    rid = genRate (undefined :: r1)


cs_mxadsr :: forall r1. KA_Signal r1
          => IFloat -> IFloat -> IFloat -> IFloat -> Orca (Sig r1)
cs_mxadsr iatt idec islev irel = 
    genOpcode1 rid "mxadsr" [ getPExpr iatt,  getPExpr idec
                            , getPExpr islev, getPExpr irel ]
  where
    rid = genRate (undefined :: r1)


cs_mxadsr_ :: forall r1. KA_Signal r1
           => IFloat -> IFloat -> IFloat -> IFloat -> IFloat 
           -> Orca (Sig r1)
cs_mxadsr_ iatt idec islev irel idel = 
    genOpcode1 rid "mxadsr" [ getPExpr iatt,  getPExpr idec
                            , getPExpr islev, getPExpr irel
                            , getPExpr idel ]
  where
    rid = genRate (undefined :: r1)

--------------------------------------------------------------------------------
-- Table access


-- | Note - index not an Int... 
--
cs_table :: forall r1. IKA_Signal r1 => Sig r1 -> TableIx -> Orca (Sig r1)
cs_table xndx ifn = 
    genOpcode1 rid "table" [ getPExpr xndx,  getPExpr ifn ]
  where
    rid = genRate (undefined :: r1)

cs_table_ :: forall r1. IKA_Signal r1
          => Sig r1 -> TableIx -> IFloat -> IFloat -> IFloat 
          -> Orca (Sig r1)
cs_table_ xndx ifn ixmode ixoff iwrap = 
    genOpcode1 rid "table" [ getPExpr xndx,   getPExpr ifn
                           , getPExpr ixmode, getPExpr ixoff
                           , getPExpr iwrap ]
  where
    rid = genRate (undefined :: r1)



cs_tablei :: forall r1. IKA_Signal r1 => Sig r1 -> TableIx -> Orca (Sig r1)
cs_tablei xndx ifn = 
    genOpcode1 rid "tablei" [ getPExpr xndx,  getPExpr ifn ]
  where
    rid = genRate (undefined :: r1)

cs_tablei_ :: forall r1. IKA_Signal r1
           => Sig r1 -> TableIx -> IFloat -> IFloat -> IFloat 
           -> Orca (Sig r1)
cs_tablei_ xndx ifn ixmode ixoff iwrap = 
    genOpcode1 rid "tablei" [ getPExpr xndx,   getPExpr ifn
                            , getPExpr ixmode, getPExpr ixoff
                            , getPExpr iwrap ]
  where
    rid = genRate (undefined :: r1)



cs_table3 :: forall r1. IKA_Signal r1 => Sig r1 -> TableIx -> Orca (Sig r1)
cs_table3 xndx ifn = 
    genOpcode1 rid "table" [ getPExpr xndx,  getPExpr ifn ]
  where
    rid = genRate (undefined :: r1)


cs_table3_ :: forall r1. IKA_Signal r1
           => Sig r1 -> TableIx -> IFloat -> IFloat -> IFloat 
           -> Orca (Sig r1)
cs_table3_ xndx ifn ixmode ixoff iwrap = 
    genOpcode1 rid "table3" [ getPExpr xndx,   getPExpr ifn
                            , getPExpr ixmode, getPExpr ixoff
                            , getPExpr iwrap ]
  where
    rid = genRate (undefined :: r1)




--------------------------------------------------------------------------------
--


cs_oscil1 :: IFloat -> KSig -> IFloat -> IInt -> Orca KSig
cs_oscil1 idel kamp idur ifn = 
    genOpcode1 K_RATE "oscil1" [ getPExpr idel, getPExpr kamp
                               , getPExpr idur, getPExpr ifn ]
         


cs_oscil1i :: IFloat -> KSig -> IFloat -> IInt -> Orca KSig
cs_oscil1i idel kamp idur ifn = 
    genOpcode1 K_RATE "oscil1i" [ getPExpr idel, getPExpr kamp
                                , getPExpr idur, getPExpr ifn ]


cs_osciln :: KSig -> IFloat -> IInt -> IFloat -> Orca KSig
cs_osciln kamp ifrq ifn itimes = 
    genOpcode1 K_RATE "osciln" [ getPExpr kamp, getPExpr ifrq
                               , getPExpr ifn,  getPExpr itimes ]


--------------------------------------------------------------------------------
-- Phasors

-- class CPhasor rate where


cs_phasor :: forall r1. KA_Signal r1 => Sig r1 -> Orca (Sig r1)
cs_phasor xcps = 
    genOpcode1 rid "phasor" [ getPExpr xcps ]
  where
    rid = genRate (undefined :: r1) 

cs_phasor_ :: forall r1. KA_Signal r1 => Sig r1 -> IFloat -> Orca (Sig r1)
cs_phasor_ xcps iphs = 
    genOpcode1 rid "phasor" [ getPExpr xcps, getPExpr iphs ]
  where
    rid = genRate (undefined :: r1) 


cs_phasorbnk :: forall r1. KA_Signal r1
             => Sig r1 -> KSig -> IFloat -> Orca (Sig r1)
cs_phasorbnk xcps kindx icnt = 
    genOpcode1 rid "phasorbnk" [ getPExpr xcps, getPExpr kindx
                               , getPExpr icnt ]
  where
    rid = genRate (undefined :: r1) 



cs_phasorbnk_  :: forall r1. KA_Signal r1
               => Sig r1 -> KSig -> IFloat -> IFloat 
               -> Orca (Sig r1)
cs_phasorbnk_ xcps kindx icnt iphs = 
    genOpcode1 rid "phasorbnk" [ getPExpr xcps, getPExpr kindx
                               , getPExpr icnt, getPExpr iphs ]
  where
    rid = genRate (undefined :: r1) 

--------------------------------------------------------------------------------
-- Basic oscillators


-- | upsample amp cps when necessary.
-- 
cs_oscil :: forall r1. KA_Signal r1 
         => Sig r1 -> Sig r1 -> TableIx -> Orca (Sig r1)
cs_oscil xamp xcps ifn = 
    genOpcode1 rid "oscil" [ getPExpr xamp, getPExpr xcps
                           , getPExpr ifn ]
  where
    rid = genRate (undefined :: r1) 


cs_oscil_ :: forall r1. KA_Signal r1
          => Sig r1 -> Sig r1 -> TableIx -> IFloat -> Orca (Sig r1)
cs_oscil_ xamp xcps ifn iphs = 
    genOpcode1 rid "oscil" [ getPExpr xamp, getPExpr xcps
                           , getPExpr ifn,  getPExpr iphs ]
  where
    rid = genRate (undefined :: r1) 




-- | Prefer @oscil@ rather than this one...
--
cs_oscili :: forall r1. KA_Signal r1
          => Sig r1 -> Sig r1 -> IInt -> Orca (Sig r1)
cs_oscili xamp xcps ifn = 
    genOpcode1 rid "oscili" [ getPExpr xamp, getPExpr xcps
                            , getPExpr ifn ]
  where
    rid = genRate (undefined :: r1) 


cs_oscili_ :: forall r1. KA_Signal r1
           => Sig r1 -> Sig r1 -> IInt -> IFloat -> Orca (Sig r1)
cs_oscili_ xamp xcps ifn iphs = 
    genOpcode1 rid "oscili" [ getPExpr xamp, getPExpr xcps
                            , getPExpr ifn,  getPExpr iphs ]
  where
    rid = genRate (undefined :: r1) 


cs_oscil3 :: forall r1. KA_Signal r1 
          => Sig r1 -> Sig r1 -> IInt -> Orca (Sig r1)
cs_oscil3 xamp xcps ifn = 
    genOpcode1 rid "oscil3"  [ getPExpr xamp, getPExpr xcps
                             , getPExpr ifn ]
  where
    rid = genRate (undefined :: r1) 


cs_oscil3_ :: forall r1. KA_Signal r1
           => Sig r1 -> Sig r1 -> IInt -> IFloat -> Orca (Sig r1)
cs_oscil3_ xamp xcps ifn iphs = 
    genOpcode1 rid "oscil3" [ getPExpr xamp, getPExpr xcps
                            , getPExpr ifn,  getPExpr iphs ]
  where
    rid = genRate (undefined :: r1) 



cs_poscil :: forall r1. KA_Signal r1
          => Sig r1 -> Sig r1 -> IInt -> Orca (Sig r1)
cs_poscil xamp xcps ift = 
    genOpcode1 rid "poscil" [ getPExpr xamp, getPExpr xcps
                            , getPExpr ift ]
  where
    rid = genRate (undefined :: r1) 

cs_poscil_ :: forall r1. KA_Signal r1
        => Sig r1 -> Sig r1 -> IInt -> IFloat -> Orca (Sig r1)
cs_poscil_ xamp xcps ift iphs = 
    genOpcode1 rid "poscil" [ getPExpr xamp, getPExpr xcps
                            , getPExpr ift,  getPExpr iphs ]
  where
    rid = genRate (undefined :: r1) 


cs_poscil3 :: forall r1. KA_Signal r1 
           => Sig r1 -> Sig r1 -> IInt -> Orca (Sig r1)
cs_poscil3 xamp xcps ift = 
    genOpcode1 rid "poscil3" [ getPExpr xamp, getPExpr xcps
                             , getPExpr ift ]
  where
    rid = genRate (undefined :: r1) 



cs_poscil3_ :: forall r1. KA_Signal r1
         => Sig r1 -> Sig r1 -> IInt -> IFloat -> Orca (Sig r1)
cs_poscil3_ xamp xcps ift iphs = 
    genOpcode1 rid "poscil3" [ getPExpr xamp, getPExpr xcps
                             , getPExpr ift,  getPExpr iphs ]
  where
    rid = genRate (undefined :: r1) 



cs_lfo :: forall r1. KA_Signal r1 => Sig r1 -> Sig r1 -> Orca (Sig r1)
cs_lfo xamp xcps = 
    genOpcode1 rid "lfo" [ getPExpr xamp, getPExpr xcps ]
  where
    rid = genRate (undefined :: r1) 


cs_lfo_ :: forall r1. KA_Signal r1 
        => Sig r1 -> Sig r1 -> IFloat -> Orca (Sig r1)
cs_lfo_ xamp xcps itype = 
    genOpcode1 rid "lfo" [ getPExpr xamp, getPExpr xcps
                         , getPExpr itype ]
  where
    rid = genRate (undefined :: r1) 

--------------------------------------------------------------------------------
-- Dynamic spectrum oscillators

-- TODO - what does the x prefix convention mean for Csound?



-- | upsample @xamp@ and @xps@ where necessary.
--
cs_buzz :: ASig -> ASig -> KSig -> IInt -> Orca ASig
cs_buzz xamp xcps knh ifn = 
    genOpcode1 A_RATE "buzz" [ getPExpr xamp, getPExpr xcps
                             , getPExpr knh,  getPExpr ifn ]


-- | upsample @xamp@ and @xps@ where necessary.
--
cs_buzz_ :: ASig -> ASig -> KSig 
         -> IInt -> IFloat -> Orca ASig
cs_buzz_ xamp xcps knh ifn iphs = 
    genOpcode1 A_RATE "buzz" [ getPExpr xamp, getPExpr xcps
                             , getPExpr knh,  getPExpr ifn
                             , getPExpr iphs ]



cs_gbuzz :: ASig -> ASig -> KSig -> KSig 
         -> KSig -> IInt -> Orca ASig
cs_gbuzz xamp xcps knh klh kr ifn = 
    genOpcode1 A_RATE "gbuzz" [ getPExpr xamp, getPExpr xcps
                              , getPExpr knh,  getPExpr klh
                              , getPExpr kr,   getPExpr ifn ]
 


cs_gbuzz_ :: ASig -> ASig -> KSig 
          -> KSig -> KSig -> IInt -> IFloat 
          -> Orca ASig
cs_gbuzz_ xamp xcps knh klh kr ifn iphs = 
    genOpcode1 A_RATE "gbuzz" [ getPExpr xamp, getPExpr xcps
                              , getPExpr knh,  getPExpr klh
                              , getPExpr kr,   getPExpr ifn
                              , getPExpr iphs ]

cs_vco :: KSig -> KSig -> IFloat -> KSig 
       -> TableIx -> IFloat -> Orca ASig
cs_vco kamp kfqc iwave kpw ifn imaxd = 
    genOpcode1 A_RATE "vco" [ getPExpr kamp,  getPExpr kfqc
                            , getPExpr iwave, getPExpr kpw
                            , getPExpr ifn,   getPExpr imaxd ]


--------------------------------------------------------------------------------
-- Additive synthesis / resynthesis


cs_adsyn :: KSig -> KSig -> KSig -> IString -> Orca ASig
cs_adsyn kamod kfmod ksmod ifilcod = 
    genOpcode1 A_RATE "adsyn" [ getPExpr kamod, getPExpr kfmod
                              , getPExpr ksmod, getPExpr ifilcod ]
    

cs_adsynt :: KSig -> KSig 
          -> TableIx -> TableIx -> TableIx -> IFloat -> Orca ASig
cs_adsynt kamp kcps iwfn ifreqfn iampfn icnt = 
    genOpcode1 A_RATE "adsynt" [ getPExpr kamp,   getPExpr kcps
                               , getPExpr iwfn,   getPExpr ifreqfn
                               , getPExpr iampfn, getPExpr icnt ]


cs_adsynt_ :: KSig -> KSig 
           -> TableIx -> TableIx -> TableIx -> IFloat -> IFloat 
           -> Orca ASig
cs_adsynt_ kamp kcps iwfn ifreqfn iampfn icnt iphs = 
    genOpcode1 A_RATE "adsynt" [ getPExpr kamp,   getPExpr kcps
                               , getPExpr iwfn,   getPExpr ifreqfn
                               , getPExpr iampfn, getPExpr icnt
                               , getPExpr iphs ]

cs_hsboscil :: KSig -> KSig -> KSig 
            -> IFloat -> TableIx -> TableIx -> Orca ASig
cs_hsboscil kamp ktone kbrite ibasfreq iwnfn ioctfn = 
    genOpcode1 A_RATE "hsboscil" [ getPExpr kamp,    getPExpr ktone
                                 , getPExpr kbrite,  getPExpr ibasfreq
                                 , getPExpr iwnfn,   getPExpr ioctfn ]

cs_hsboscil_ :: KSig -> KSig -> KSig 
             -> IFloat -> TableIx -> TableIx -> IFloat -> IFloat
             -> Orca ASig
cs_hsboscil_ kamp ktone kbrite ibasfreq iwnfn ioctfn ioctcnt iphs = 
    genOpcode1 A_RATE "hsboscil" [ getPExpr kamp,    getPExpr ktone
                                 , getPExpr kbrite,  getPExpr ibasfreq
                                 , getPExpr iwnfn,   getPExpr ioctfn
                                 , getPExpr ioctcnt, getPExpr iphs ]


--------------------------------------------------------------------------------
-- FM Synthesis



cs_foscil :: ASig -> KSig -> KSig -> KSig -> KSig -> TableIx
          -> Orca ASig
cs_foscil xamp kcps kcar kmod kndx ifn = 
    genOpcode1 A_RATE "foscil" [ getPExpr xamp, getPExpr kcps
                               , getPExpr kcar, getPExpr kmod
                               , getPExpr kndx, getPExpr ifn ]


cs_foscil_ :: ASig -> KSig -> KSig 
           -> KSig -> KSig -> TableIx -> IFloat 
           -> Orca ASig
cs_foscil_ xamp kcps kcar kmod kndx ifn iphs = 
    genOpcode1 A_RATE "foscil" [ getPExpr xamp, getPExpr kcps
                               , getPExpr kcar, getPExpr kmod
                               , getPExpr kndx, getPExpr ifn
                               , getPExpr iphs ]



cs_foscili :: ASig -> KSig -> KSig 
           -> KSig -> KSig -> TableIx
           -> Orca ASig
cs_foscili xamp kcps kcar kmod kndx ifn = 
    genOpcode1 A_RATE "foscili" [ getPExpr xamp, getPExpr kcps
                                , getPExpr kcar, getPExpr kmod
                                , getPExpr kndx, getPExpr ifn ]


-- | Upsample @xamp@ if necessary.
--
cs_foscili_ :: ASig -> KSig -> KSig 
            -> KSig -> KSig -> TableIx -> IFloat 
            -> Orca ASig
cs_foscili_ xamp kcps kcar kmod kndx ifn iphs = 
    genOpcode1 A_RATE "foscili" [ getPExpr xamp, getPExpr kcps
                                , getPExpr kcar, getPExpr kmod
                                , getPExpr kndx, getPExpr ifn
                                , getPExpr iphs ]


cs_fmvoice :: KSig -> KSig -> KSig 
           -> KSig -> KSig -> KSig
           -> TableIx -> TableIx -> TableIx -> TableIx -> TableIx
           -> Orca ASig
cs_fmvoice kamp kfreq kvowel ktilt kvibamt kvibrate ifn1 ifn2 ifn3 ifn4 ifnv = 
    genOpcode1 A_RATE "fmvoice" [ getPExpr kamp,    getPExpr kfreq
                                , getPExpr kvowel,  getPExpr ktilt
                                , getPExpr kvibamt, getPExpr kvibrate
                                , getPExpr ifn1,    getPExpr ifn2
                                , getPExpr ifn3,    getPExpr ifn4
                                , getPExpr ifnv ]

cs_fmbell :: KSig -> KSig -> KSig 
          -> KSig -> KSig -> KSig
          -> TableIx -> TableIx -> TableIx -> TableIx -> TableIx
          -> Orca ASig
cs_fmbell kamp kfreq kc1 kc2 kvdepth kvrate ifn1 ifn2 ifn3 ifn4 ifnv = 
    genOpcode1 A_RATE "fmbell" [ getPExpr kamp,    getPExpr kfreq
                               , getPExpr kc1,     getPExpr kc2
                               , getPExpr kvdepth, getPExpr kvrate
                               , getPExpr ifn1,    getPExpr ifn2
                               , getPExpr ifn3,    getPExpr ifn4
                               , getPExpr ifnv ]


cs_fmrhode :: KSig -> KSig -> KSig 
           -> KSig -> KSig -> KSig
           -> TableIx -> TableIx -> TableIx -> TableIx -> TableIx
           -> Orca ASig
cs_fmrhode kamp kfreq kc1 kc2 kvdepth kvrate ifn1 ifn2 ifn3 ifn4 ifnv = 
    genOpcode1 A_RATE "fmrhode" [ getPExpr kamp,    getPExpr kfreq
                                , getPExpr kc1,     getPExpr kc2
                                , getPExpr kvdepth, getPExpr kvrate
                                , getPExpr ifn1,    getPExpr ifn2
                                , getPExpr ifn3,    getPExpr ifn4
                                , getPExpr ifnv ]

cs_fmwurlie :: KSig -> KSig -> KSig 
            -> KSig -> KSig -> KSig
            -> TableIx -> TableIx -> TableIx -> TableIx -> TableIx
            -> Orca ASig
cs_fmwurlie kamp kfreq kc1 kc2 kvdepth kvrate ifn1 ifn2 ifn3 ifn4 ifnv = 
    genOpcode1 A_RATE "fmwurlie" [ getPExpr kamp,    getPExpr kfreq
                                 , getPExpr kc1,     getPExpr kc2
                                 , getPExpr kvdepth, getPExpr kvrate
                                 , getPExpr ifn1,    getPExpr ifn2
                                 , getPExpr ifn3,    getPExpr ifn4
                                 , getPExpr ifnv ]


cs_fmmetal :: KSig -> KSig -> KSig 
           -> KSig -> KSig -> KSig
           -> TableIx -> TableIx -> TableIx -> TableIx -> TableIx
           -> Orca ASig
cs_fmmetal kamp kfreq kc1 kc2 kvdepth kvrate ifn1 ifn2 ifn3 ifn4 ifnv = 
    genOpcode1 A_RATE "fmmetal" [ getPExpr kamp,    getPExpr kfreq
                                , getPExpr kc1,     getPExpr kc2
                                , getPExpr kvdepth, getPExpr kvrate
                                , getPExpr ifn1,    getPExpr ifn2
                                , getPExpr ifn3,    getPExpr ifn4
                                , getPExpr ifnv ]


cs_fmb3 :: KSig -> KSig -> KSig 
        -> KSig -> KSig -> KSig
        -> TableIx -> TableIx -> TableIx -> TableIx -> TableIx
        -> Orca ASig
cs_fmb3 kamp kfreq kc1 kc2 kvdepth kvrate ifn1 ifn2 ifn3 ifn4 ifnv = 
    genOpcode1 A_RATE "fmb3" [ getPExpr kamp,    getPExpr kfreq
                             , getPExpr kc1,     getPExpr kc2
                             , getPExpr kvdepth, getPExpr kvrate
                             , getPExpr ifn1,    getPExpr ifn2
                             , getPExpr ifn3,    getPExpr ifn4
                             , getPExpr ifnv ]

cs_fmpercfl :: KSig -> KSig -> KSig 
            -> KSig -> KSig -> KSig        
            -> TableIx -> TableIx -> TableIx -> TableIx -> TableIx
            -> Orca ASig
cs_fmpercfl kamp kfreq kc1 kc2 kvdepth kvrate ifn1 ifn2 ifn3 ifn4 ifnv = 
    genOpcode1 A_RATE "fmpercfl" [ getPExpr kamp,    getPExpr kfreq
                                 , getPExpr kc1,     getPExpr kc2
                                 , getPExpr kvdepth, getPExpr kvrate
                                 , getPExpr ifn1,    getPExpr ifn2
                                 , getPExpr ifn3,    getPExpr ifn4
                                 , getPExpr ifnv ]


--------------------------------------------------------------------------------
-- Sample playback

-- Note - it seems idiomatic to want a stereo version with only
-- the mandatory args...


-- | Note - use 1 for ibase and kcps if the frequency is not known.
--
cs_loscil :: forall r1. KA_Signal r1
          => Sig r1 -> KSig -> TableIx -> Orca ASig
cs_loscil xamp kcps ifn = 
    genOpcode1 A_RATE "loscil" [ getPExpr xamp,    getPExpr kcps
                               , getPExpr ifn ]



-- | Stereo version of 'loscil'.
--
-- Note - use 1 for ibase and kcps if the frequency is not known.
--
cs_loscilS :: forall r1. KA_Signal r1 
           => Sig r1 -> KSig -> TableIx
           -> Orca (ASig,ASig)
cs_loscilS xamp kcps ifn = 
    genOpcode2 A_RATE "loscil" [ getPExpr xamp,    getPExpr kcps
                               , getPExpr ifn ]




-- | Note - use 1 for ibase and kcps if the frequency is not known.
-- upsample @xamp@ if necessary.
--
cs_loscil3 :: forall r1. KA_Signal r1
           => Sig r1 -> KSig -> TableIx -> Orca ASig
cs_loscil3 xamp kcps ifn = 
    genOpcode1 A_RATE "loscil3" [ getPExpr xamp, getPExpr kcps
                                , getPExpr ifn ]



-- | Stereo version of 'loscil3'.
--
-- Note - use 1 for ibase and kcps if the frequency is not known.
-- upsample @xamp@ if necessary.
--
cs_loscil3S :: forall r1. KA_Signal r1 
            => Sig r1 -> KSig -> TableIx -> Orca (ASig,ASig)
cs_loscil3S xamp kcps ifn = 
    genOpcode2 A_RATE "loscil3" [ getPExpr xamp, getPExpr kcps
                                , getPExpr ifn ]



cs_lposcil :: KSig -> KSig 
           -> KSig -> KSig -> TableIx
           -> Orca ASig
cs_lposcil kamp kfreqratio kloop kend ift = 
    genOpcode1 A_RATE "lposcil" [ getPExpr kamp,  getPExpr kfreqratio
                                , getPExpr kloop, getPExpr kend
                                , getPExpr ift ]



cs_lposcil3 :: KSig -> KSig 
            -> KSig -> KSig -> TableIx
            -> Orca ASig
cs_lposcil3 kamp kfreqratio kloop kend ift = 
    genOpcode1 A_RATE "lposcil3" [ getPExpr kamp,  getPExpr kfreqratio
                                 , getPExpr kloop, getPExpr kend
                                 , getPExpr ift ]


--------------------------------------------------------------------------------
-- Granular synthesis

cs_fof :: forall r1. IKA_Signal r1
       => Sig r1  -> Sig r1  -> Sig r1
       -> KSig -> KSig -> KSig
       -> KSig -> KSig -> IInt
       -> TableIx -> TableIx -> IFloat
       -> Orca ASig
cs_fof xamp xfund xform koct kband kris kdur kdec iolaps ifna ifnb itotdur = 
    genOpcode1 A_RATE "fof" [ getPExpr xamp,   getPExpr xfund
                            , getPExpr xform,  getPExpr koct
                            , getPExpr kband,  getPExpr kris
                            , getPExpr kdur,   getPExpr kdec
                            , getPExpr iolaps, getPExpr ifna
                            , getPExpr ifnb,   getPExpr itotdur ]




cs_fof2 :: forall r1. IKA_Signal r1
        => Sig r1 -> Sig r1  -> Sig r1
        -> KSig -> KSig -> KSig
        -> KSig -> KSig -> IInt
        -> TableIx -> TableIx -> IFloat
        -> KSig -> KSig
        -> Orca ASig
cs_fof2 xamp xfund xform koct kband kris kdur kdec iolaps ifna ifnb itotdur 
     kphs kgliss = 
    genOpcode1 A_RATE "fof2" [ getPExpr xamp,   getPExpr xfund
                             , getPExpr xform,  getPExpr koct
                             , getPExpr kband,  getPExpr kris
                             , getPExpr kdur,   getPExpr kdec
                             , getPExpr iolaps, getPExpr ifna
                             , getPExpr ifnb,   getPExpr itotdur 
                             , getPExpr kphs,   getPExpr kgliss ]



-- | 
--
-- > fog : xamp * xdens * xtrans * aspd * 
-- >       koct * kband * kris * kdur * kdec *
-- >       iolaps * ifna * ifnb * itotdur
-- >      -> ares
--
-- Note - kband etc. are not perhaps signals. 
-- Or maybe they are see @grain@...
--
cs_fog :: forall r1. IKA_Signal r1
       => Sig r1 -> Sig r1 -> Sig r1
       -> Sig r1 -> KSig -> KSig
       -> KSig -> KSig -> KSig
       -> IFloat -> TableIx -> TableIx 
       -> IFloat
       -> Orca ASig
cs_fog xamp xdens xtrans xspd koct kband kris kdur kdec iolaps 
       ifna ifnb itotdur = 
    genOpcode1 A_RATE "fog" [ getPExpr xamp,   getPExpr xdens
                            , getPExpr xtrans, getPExpr xspd
                            , getPExpr koct,   getPExpr kband
                            , getPExpr kris,   getPExpr kdur
                            , getPExpr kdec,   getPExpr iolaps
                            , getPExpr ifna,   getPExpr ifnb
                            , getPExpr itotdur ]
    
-- | 
-- 
-- > grain : xamp * xpitch * xdens * kampoff * 
-- >         kpitchoff * kgdur * igfn * iwfn * imgdur
-- >        -> ares

cs_grain :: forall r1. IKA_Signal r1
         => Sig r1 -> Sig r1 -> Sig r1
         -> KSig -> KSig -> KSig
         -> TableIx -> TableIx -> IFloat
         -> Orca ASig
cs_grain xamp xpitch xdens kampoff kpitchoff kgdur igfn iwfn imgdur = 
    genOpcode1 A_RATE "grain" [ getPExpr xamp,      getPExpr xpitch
                              , getPExpr xdens,     getPExpr kampoff
                              , getPExpr kpitchoff, getPExpr kgdur
                              , getPExpr igfn,      getPExpr iwfn
                              , getPExpr imgdur ]


cs_grain2 :: KSig -> KSig -> KSig -> IInt -> TableIx -> TableIx -> Orca ASig
cs_grain2 kcps kfmd kgdur iovrlp kfn iwfn = 
    genOpcode1 A_RATE "grain2" [ getPExpr kcps,  getPExpr kfmd
                               , getPExpr kgdur, getPExpr iovrlp
                               , getPExpr kfn,   getPExpr iwfn ] 



cs_grain3 :: KSig -> KSig -> KSig -> KSig -> KSig -> KSig
          -> IInt -> TableIx -> TableIx -> KSig -> KSig
          -> Orca ASig
cs_grain3 kcps kphs kfmd kpmd kgdur kdens imaxovr kfn iwfn kfrpow kprpow = 
    genOpcode1 A_RATE "grain3" [ getPExpr kcps,    getPExpr kphs
                               , getPExpr kfmd,    getPExpr kpmd
                               , getPExpr kgdur,   getPExpr kdens
                               , getPExpr imaxovr, getPExpr kfn
                               , getPExpr iwfn,    getPExpr kfrpow
                               , getPExpr kprpow ] 

-- |
-- 
-- > granule : xamp * ivoice * iratio * imode * ithd
-- >           ifn * ipshift * igskip * igskip_os * 
-- >           ilength * kgap * igap_os * kgsize * 
-- >           igsize_os * iatt * idec
-- >          -> ares
--
cs_granule :: forall r1. IKA_Signal r1
           => Sig r1 -> IInt -> IFloat
           -> IInt -> IFloat -> TableIx
           -> IInt -> IFloat -> IFloat
           -> IFloat -> KSig -> IFloat 
           -> KSig -> IFloat -> IFloat 
           -> IFloat                
           -> Orca ASig 
cs_granule xamp ivoice iratio imode ithd ifn ipshift igskip igskip_os
        ilength kgap igap_os kgsize igsize_os iatt idec = 
    genOpcode1 A_RATE "granule" [ getPExpr xamp,      getPExpr ivoice
                                , getPExpr iratio,    getPExpr imode
                                , getPExpr ithd,      getPExpr ifn
                                , getPExpr ipshift,   getPExpr igskip
                                , getPExpr igskip_os, getPExpr ilength
                                , getPExpr kgap,      getPExpr igap_os
                                , getPExpr kgsize,    getPExpr igsize_os
                                , getPExpr iatt,      getPExpr idec ]



-- Note - not all k rate values are /signals/ (reals) the can be 
-- function table numbers as well. For these we use TableIx 
-- rather than KSig.

cs_partikkel :: ASig -> KSig -> TableIx -> ASig -> KSig
             -> TableIx -> TableIx -> TableIx -> KSig -> KSig 
             -> KSig -> KSig -> TableIx -> KSig -> KSig
             -> TableIx -> TableIx -> ASig -> TableIx -> KSig 
             -> TableIx -> KSig -> KSig -> KSig -> TableIx
             -> KSig -> TableIx -> TableIx -> TableIx -> TableIx
             -> TableIx -> ASig -> ASig -> ASig -> ASig
             -> KSig -> KSig -> KSig -> KSig -> IInt 
             -> Orca ASig
cs_partikkel agrainfreq kdistribution idisttab async kenv2amt
          ienv2tab ienv_attack ienv_decay ksustain_amount ka_d_ratio
          kduration kamp igainmasks kwavfreq ksweepshape
          iwavfreqstarttab iwavfreqendtab awavfm ifmamptab kfmenv
          icosine ktraincps knumpartials kchroma ichannelmasks 
          krandommask kwaveform1 kwaveform2 kwaveform3 kwaveform4
          iwaveamptab asamplepos1 asamplepos2 asamplepos3 asamplepos4
          kwavekey1 kwavekey2 kwavekey3 kwavekey4 imax_grains = 
    genOpcode1 A_RATE "partikkel" $
              [ getPExpr agrainfreq,      getPExpr kdistribution 
              , getPExpr idisttab,        getPExpr async
              , getPExpr kenv2amt,        getPExpr ienv2tab 
              , getPExpr ienv_attack,     getPExpr ienv_decay
              , getPExpr ksustain_amount, getPExpr ka_d_ratio
              , getPExpr kduration,       getPExpr kamp
              , getPExpr igainmasks,      getPExpr kwavfreq
              , getPExpr ksweepshape,     getPExpr iwavfreqstarttab
              , getPExpr iwavfreqendtab,  getPExpr awavfm
              , getPExpr ifmamptab,       getPExpr kfmenv
              , getPExpr icosine,         getPExpr ktraincps
              , getPExpr knumpartials,    getPExpr kchroma
              , getPExpr ichannelmasks,   getPExpr krandommask
              , getPExpr kwaveform1,      getPExpr kwaveform2
              , getPExpr kwaveform3,      getPExpr kwaveform4
              , getPExpr iwaveamptab,     getPExpr asamplepos1
              , getPExpr asamplepos2,     getPExpr asamplepos3
              , getPExpr asamplepos4,     getPExpr kwavekey1
              , getPExpr kwavekey2,       getPExpr kwavekey3
              , getPExpr kwavekey4,       getPExpr imax_grains ]




--------------------------------------------------------------------------------
-- Models and emulations

cs_moog :: KSig -> KSig -> KSig 
        -> KSig -> KSig -> KSig
        -> TableIx -> TableIx -> TableIx
        -> Orca ASig
cs_moog kamp kfreq kfiltq kfiltrate kvibf kvamp iafn iwfn ivfn = 
    genOpcode1 A_RATE "moog" [ getPExpr kamp,   getPExpr kfreq
                             , getPExpr kfiltq, getPExpr kfiltrate
                             , getPExpr kvibf,  getPExpr kvamp
                             , getPExpr iafn,   getPExpr iwfn
                             , getPExpr ivfn ]


-- | idecay - default is 0
--
cs_shaker :: KSig -> KSig -> KSig 
          -> KSig -> KSig -> IFloat
          -> Orca ASig
cs_shaker kamp kfreq kbeans kdamp ktimes idecay = 
    genOpcode1 A_RATE "shaker" [ getPExpr kamp,   getPExpr kfreq
                               , getPExpr kbeans, getPExpr kdamp
                               , getPExpr ktimes, getPExpr idecay ]


cs_marimba :: KSig -> KSig -> IFloat -> IFloat 
           -> IInt  -> KSig -> KSig 
           -> TableIx  -> IFloat
           -> Orca ASig
cs_marimba kamp kfreq ihrd ipos imp kvibf kvamp ivibfn idec = 
    genOpcode1 A_RATE "marimba" [ getPExpr kamp,  getPExpr kfreq
                                , getPExpr ihrd,  getPExpr ipos
                                , getPExpr imp,   getPExpr kvibf
                                , getPExpr kvamp, getPExpr ivibfn
                                , getPExpr idec ]

cs_vibes :: KSig -> KSig -> IFloat -> IFloat 
         -> IInt  -> KSig -> KSig   
         -> TableIx  -> IFloat
         -> Orca ASig
cs_vibes kamp kfreq ihrd ipos imp kvibf kvamp ivibfn idec = 
    genOpcode1 A_RATE "vibes" [ getPExpr kamp,  getPExpr kfreq
                              , getPExpr ihrd,  getPExpr ipos
                              , getPExpr imp,   getPExpr kvibf
                              , getPExpr kvamp, getPExpr ivibfn
                              , getPExpr idec ]

-- | iminfreq - default 0
--
cs_mandol :: KSig -> KSig -> KSig 
          -> KSig -> KSig -> KSig 
          -> IInt -> IFloat
          -> Orca ASig
cs_mandol kamp kfreq kpluck kdetune kgain ksize ifn iminfreq = 
    genOpcode1 A_RATE "marimba" [ getPExpr kamp,   getPExpr kfreq
                                , getPExpr kpluck, getPExpr kdetune
                                , getPExpr kgain,  getPExpr ksize
                                , getPExpr ifn,    getPExpr iminfreq ]


cs_gogobel :: KSig  -> KSig 
           -> IFloat -> IFloat -> IFloat 
           -> KSig  -> KSig  -> TableIx
           -> Orca ASig
cs_gogobel kamp kfreq ihrd ipos imp kvibf kvamp ivfn = 
    genOpcode1 A_RATE "gogobel" [ getPExpr kamp,  getPExpr kfreq
                                , getPExpr ihrd,  getPExpr ipos
                                , getPExpr imp,   getPExpr kvibf
                                , getPExpr kvamp, getPExpr ivfn ]


cs_voice :: KSig -> KSig -> KSig 
         -> KSig -> KSig -> KSig
         -> TableIx -> TableIx
         -> Orca ASig
cs_voice kamp kfreq kphoneme kform kvibf kvamp ifn ivfn = 
    genOpcode1 A_RATE "voice" [ getPExpr kamp,     getPExpr kfreq
                              , getPExpr kphoneme, getPExpr kform
                              , getPExpr kvibf,    getPExpr kvamp
                              , getPExpr ifn,      getPExpr ivfn ]

cs_lorenz :: KSig  -> KSig  -> KSig   -> KSig 
          -> IFloat -> IFloat -> IFloat -> IFloat
          -> Orca (ASig,ASig,ASig)
cs_lorenz ks kr kb kh ix iy iz iskip =  
    genOpcode3 A_RATE "lorenz" [ getPExpr ks, getPExpr kr
                               , getPExpr kb, getPExpr kh
                               , getPExpr ix, getPExpr iy
                               , getPExpr iz, getPExpr iskip ]

cs_planet :: KSig  -> KSig   -> KSig 
          -> IFloat -> IFloat -> IFloat 
          -> IFloat -> IFloat -> IFloat 
          -> IFloat -> IFloat
          -> Orca (ASig,ASig,ASig)
cs_planet kmass1 kmass2 ksep ix iy iz ivx ivy ivz idelta ifriction = 
    genOpcode3 A_RATE "planet" [ getPExpr kmass1, getPExpr kmass2
                               , getPExpr ksep,   getPExpr ix
                               , getPExpr iy,     getPExpr iz
                               , getPExpr ivx,    getPExpr ivy
                               , getPExpr ivz,    getPExpr idelta
                               , getPExpr ifriction ]



--------------------------------------------------------------------------------
-- Random noise generators



cs_rand :: forall r1. KA_Signal r1 => Sig r1 -> Orca (Sig r1)
cs_rand xamp = 
    genOpcode1 rid "rand" [ getPExpr xamp ]
  where
    rid = genRate (undefined :: r1)

cs_randh :: forall r1. KA_Signal r1 => Sig r1 -> Sig r1 -> Orca (Sig r1)
cs_randh xamp xcps = 
    genOpcode1 rid "rand" [ getPExpr xamp, getPExpr xcps ]
  where
    rid = genRate (undefined :: r1)


cs_randi :: forall r1. KA_Signal r1 => Sig r1 -> Sig r1 -> Orca (Sig r1)
cs_randi xamp xcps = 
    genOpcode1 rid "rand" [ getPExpr xamp, getPExpr xcps ]
  where
    rid = genRate (undefined :: r1)



cs_linrand :: forall r1. IKA_Signal r1 =>  KSig -> Orca (Sig r1)
cs_linrand krange = 
    genOpcode1 rid "linrand" [ getPExpr krange ]
  where
    rid = genRate (undefined :: r1)



cs_trirand :: forall r1. IKA_Signal r1 => KSig -> Orca (Sig r1)
cs_trirand krange = 
    genOpcode1 rid "trirand" [ getPExpr krange ]
  where
    rid = genRate (undefined :: r1)



cs_exprand :: forall r1. IKA_Signal r1 => KSig -> Orca (Sig r1)
cs_exprand krange = 
    genOpcode1 rid "exprand" [ getPExpr krange ]
  where
    rid = genRate (undefined :: r1)


cs_bexprand :: forall r1. IKA_Signal r1 => KSig -> Orca (Sig r1)
cs_bexprand krange = 
    genOpcode1 rid "bexprand" [ getPExpr krange ]
  where
    rid = genRate (undefined :: r1)


cs_cauchy :: forall r1. IKA_Signal r1 => KSig -> Orca (Sig r1)
cs_cauchy kalpha = 
    genOpcode1 rid "cauchy" [ getPExpr kalpha ]
  where
    rid = genRate (undefined :: r1)


cs_pcauchy :: forall r1. IKA_Signal r1 => KSig -> Orca (Sig r1)
cs_pcauchy kalpha = 
    genOpcode1 rid "pcauchy" [ getPExpr kalpha ]
  where
    rid = genRate (undefined :: r1)


cs_poisson :: forall r1. IKA_Signal r1 =>  KSig -> Orca (Sig r1)
cs_poisson klambda = 
    genOpcode1 rid "poisson" [ getPExpr klambda ]
  where
    rid = genRate (undefined :: r1)


cs_gauss :: forall r1. IKA_Signal r1 => KSig -> Orca (Sig r1)
cs_gauss krange = 
    genOpcode1 rid "gauss" [ getPExpr krange ]
  where
    rid = genRate (undefined :: r1)

cs_weibull :: forall r1. IKA_Signal r1 => KSig -> KSig -> Orca (Sig r1)
cs_weibull ksigma ktau = 
   genOpcode1 rid "weibull" [ getPExpr ksigma, getPExpr ktau ]
  where
    rid = genRate (undefined :: r1)


cs_betarand :: forall r1. IKA_Signal r1 
            => KSig -> KSig -> KSig -> Orca (Sig r1)
cs_betarand krange kalpha kbeta = 
    genOpcode1 rid "betarand" [ getPExpr krange, getPExpr kalpha
                              , getPExpr kbeta ]
  where
    rid = genRate (undefined :: r1)


-- Note - can make IRate value from a KRate value, odd...

cs_unirand :: forall r1. IKA_Signal r1 => KSig -> Orca (Sig r1)
cs_unirand krange = 
    genOpcode1 rid "unirand" [ getPExpr krange ]
  where
    rid = genRate (undefined :: r1)



--------------------------------------------------------------------------------
-- Waveguide physical modeling

cs_pluck  :: KSig -> KSig -> IFloat -> TableIx -> IInt -> Orca ASig
cs_pluck kamp kcps icps ifn imeth = 
    genOpcode1 A_RATE "pluck" [ getPExpr kamp, getPExpr kcps
                              , getPExpr icps, getPExpr ifn
                              , getPExpr imeth ]


cs_repluck :: IFloat -> KSig -> IFloat -> KSig -> KSig -> ASig -> Orca ASig
cs_repluck iplk kamp icps kpick krefl axcite =
    genOpcode1 A_RATE "repluck" [ getPExpr iplk,  getPExpr kamp
                                , getPExpr icps,  getPExpr kpick
                                , getPExpr krefl, getPExpr axcite ]


cs_wgbow :: KSig -> KSig -> KSig -> KSig -> KSig -> KSig -> TableIx 
         -> Orca ASig
cs_wgbow kamp kfreq kpres krat kvibf kvamp ifn =
    genOpcode1 A_RATE "repluck" [ getPExpr kamp,  getPExpr kfreq
                                , getPExpr kpres, getPExpr krat
                                , getPExpr kvibf, getPExpr kvamp
                                , getPExpr ifn ]



cs_wgbowedbar :: KSig -> KSig -> KSig -> KSig -> KSig -> Orca ASig
cs_wgbowedbar kamp kfreq kpos kbowpres kgain = 
    genOpcode1 A_RATE "wgbowedbar" [ getPExpr kamp, getPExpr kfreq
                                   , getPExpr kpos, getPExpr kbowpres
                                   , getPExpr kgain ]
             


cs_wgbrass :: KSig -> KSig -> KSig -> IFloat -> KSig -> KSig -> TableIx 
           -> Orca ASig
cs_wgbrass kamp kfreq ktens iatt kvibf kvamp ifn = 
    genOpcode1 A_RATE "wgbrass" [ getPExpr kamp,  getPExpr kfreq
                                , getPExpr ktens, getPExpr iatt
                                , getPExpr kvibf, getPExpr kvamp
                                , getPExpr ifn ]

cs_wgclar :: KSig -> KSig -> KSig -> IFloat -> IFloat
          -> KSig -> KSig -> KSig -> TableIx
          -> Orca ASig
cs_wgclar kamp kfreq kstiff iatt idetk kngain kvibf kvamp ifn = 
    genOpcode1 A_RATE "wgclar" [ getPExpr kamp,   getPExpr kfreq
                               , getPExpr kstiff, getPExpr iatt
                               , getPExpr idetk,  getPExpr kngain
                               , getPExpr kvibf,  getPExpr kvamp
                               , getPExpr ifn ]

cs_wgflute :: KSig -> KSig -> KSig -> IFloat -> IFloat
           -> KSig -> KSig -> KSig -> TableIx
           -> Orca ASig
cs_wgflute kamp kfreq kjet iatt idetk kngain kvibf kvamp ifn = 
    genOpcode1 A_RATE "wgflute" [ getPExpr kamp,   getPExpr kfreq
                                , getPExpr kjet,   getPExpr iatt
                                , getPExpr idetk,  getPExpr kngain
                                , getPExpr kvibf,  getPExpr kvamp
                                , getPExpr ifn ]

cs_wgpluck :: IFloat -> IFloat -> KSig -> IFloat -> IFloat -> IFloat -> ASig
           -> Orca ASig
cs_wgpluck icps iamp kpick iplk idamp ifilt axcite = 
    genOpcode1 A_RATE "wgpluck" [ getPExpr icps,  getPExpr iamp
                                , getPExpr kpick, getPExpr iplk
                                , getPExpr idamp, getPExpr ifilt
                                , getPExpr axcite ]

cs_wgpluck2 :: IFloat -> KSig -> IFloat -> KSig -> KSig -> Orca ASig
cs_wgpluck2 iplk kamp icps kpick krefl = 
    genOpcode1 A_RATE "wgpluck2" [ getPExpr iplk, getPExpr kamp
                                 , getPExpr icps, getPExpr kpick
                                 , getPExpr krefl ]

cs_wguide1 :: KA_Signal a => ASig -> Sig a -> KSig -> KSig -> Orca ASig
cs_wguide1 asig xfreq kcutoff kfeedback = 
    genOpcode1 A_RATE "wguide1" [ getPExpr asig,    getPExpr xfreq
                                , getPExpr kcutoff, getPExpr kfeedback ]


cs_wguide2 :: (KA_Signal a, KA_Signal b)
           => ASig -> Sig a -> Sig b -> KSig -> KSig -> KSig -> KSig 
           -> Orca ASig
cs_wguide2 asig xfreq1 xfreq2 kcutoff1 kcutoff2 kfeedback1 kfeedback2 =
    genOpcode1 A_RATE "wguide2" [ getPExpr asig,      getPExpr xfreq1
                                , getPExpr xfreq2,    getPExpr kcutoff1
                                , getPExpr kcutoff2,  getPExpr kfeedback1
                                , getPExpr  kfeedback2 ]

